package com.mayflygeek.mayflyask.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.mayflygeek.mayflyask.dao.RoleDao;
import com.mayflygeek.mayflyask.entity.Role;
import com.mayflygeek.mayflyask.service.RoleService;
/**
 * @author 蝈蝈 
 * @email guodefu909@126.com
 * @team 蜉蝣极客
 * @link www.mayflygeek.com
 */
@Service
@Transactional
public class RoleServiceImpl implements RoleService{
	
	/* @Resource的作用相当于@Autowired
	 * @Autowired是spring自己定义的，@Resource是JSR-250规范定义的
	 * 推荐使用：@Resource，减少了与spring的耦合。
	 * 两者的更多区别参考：http://blog.csdn.net/gst6062825/article/details/8765157*/
	@Resource
	private RoleDao roleDao;

	@Override
	public void saveRole(Role role) {
		roleDao.save(role);
	}

	@Override
	public void deleteRole(Long id) {
		roleDao.delete(id);
	}

	@Override
	public void deleteRole(Role role) {
		roleDao.delete(role);
	}

	@Override
	public void deleteRoles(List<Role> roles) {
		roleDao.deleteInBatch(roles);
	}
	
	@Override
	public Role updateRole(Role role) {
		return roleDao.saveAndFlush(role);
	}

	@Override
	public Role updateRoleStatus(Long id, Integer status) {
		return roleDao.updateRoleStatus(id, status);
	}

	@Override
	@Transactional(readOnly=true)
	public Role getRole(Long id) {
		return roleDao.findOne(id);
	}
	
	@Override
	@Transactional(readOnly=true)
	public Role getByRoleName(String roleName) {
		return roleDao.getByRoleName(roleName);
	}
	
	@Override
	@Transactional(readOnly=true)
	public List<Role> getAllRole() {
		return roleDao.findAll();
	}
	
	

}
